﻿
Namespace MVVM

    Public MustInherit Class ClosableViewModelBase
        Inherits ViewModelBase

#Region " Declarations "

        Private _cmdRequestCloseCommand As ICommand

#End Region

#Region " Events "

        Public Event RequestClose As EventHandler

#End Region

#Region " Command Properties "

        Public ReadOnly Property RequestCloseCommand() As ICommand
            Get

                If _cmdRequestCloseCommand Is Nothing Then
                    _cmdRequestCloseCommand = New RelayCommand(AddressOf Me.RequestCloseExecute)
                End If

                Return _cmdRequestCloseCommand
            End Get
        End Property

#End Region

#Region " Constructor "

        Public Sub New()
        End Sub

#End Region

#Region " Methods "

        Protected Overridable Sub OnRequestClose()

            If Me.RequestCloseEvent IsNot Nothing Then
                RaiseEvent RequestClose(Me, New EventArgs)
            End If

        End Sub

        Private Sub RequestCloseExecute(ByVal param As Object)
            OnRequestClose()
        End Sub

#End Region

    End Class

End Namespace
